﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using Users;
using Lists;
using Sim;

namespace Lists
{
    [Serializable()]
    public class DiverList
    {
        public List<Diver> diverList { get; set; }

        public DiverList()
        {
            diverList = new List<Diver>();
        }

        public int AddDiver(Diver d)
        {
            for (int i = 0; i < diverList.Count(); i++)
            {
                if (d.username == diverList[i].username)
                {
                    return 0;
                }
            }
            for (int i = 0; i < UserList.userList.Count(); i++)
            {
                if (d.username == UserList.userList[i].username && d.level == 0 && UserList.userList[i].level == 0)
                {
                    d.id = UserList.userList[i].id;
                    diverList.Add(d);
                    break;
                }
            }
            return 1;
        }

        public int AddDiver(string username)
        {
            for (int i = 0; i < diverList.Count(); i++)
            {
 
                if (username == diverList[i].username)
                {
                    return 0;
                }
            }
            for (int i = 0; i < UserList.userList.Count(); i++)
            {
                if (username == UserList.userList[i].username && UserList.userList[i].level == 0)
                {
                    Diver d = new Diver();
                    d.id = UserList.userList[i].id;
                    d.firstName = UserList.userList[i].firstName;
                    d.lastName = UserList.userList[i].lastName;
                    d.age = UserList.userList[i].age;
                    d.nation = UserList.userList[i].nation;
                    d.sex = UserList.userList[i].sex;
                    d.username = UserList.userList[i].username;
                    diverList.Add(d);
                    break;
                }
            }
            return 1;
        }

        public void RemoveDiver(int index)
        {
            diverList.RemoveAt(index);
        }
    }
}
